<?php


namespace app\queue\stomp;


use app\queue\BaseConsumer;
use common\service\EntityService;
use Webman\Stomp\RetryAbleConsumer;

/**
 * 批量导入剧本的清单
 * Class CalculateEntityManHourConsumer
 * @package app\queue\redis
 */
class FillBackScriptDetailedListDataConsumer extends BaseConsumer implements RetryAbleConsumer
{
    // 要消费的队列名
    public $queue = 'fill_back_script_detailed_list_data';

    // 连接名，对应 config/redis_queue.php 里的连接`
    public $connection = 'default';

    /**
     * 批量导入剧本的清单
     * @param $data
     * @return void
     * @throws \Throwable
     */
    public function doConsume($data)
    {
        $entityService = EntityService::getInstance();
        $data = array_filter($data['data'], function ($item) {
            return !empty($item['showings_number']);
        });
        if (empty($data)) {
            return;
        }
        $data = array_values($data);
        $entityService->fillBackScriptDetailedListData($data);
    }

    public function getTtr()
    {
        return 10;
    }

    public function canRetry($attempt, $error)
    {
        trace(format_exception_info($error), 'ERR');
        return $attempt <= 10;
    }
}
